﻿// =================================================================== 
// 项目说明
//====================================================================
// liucx @Copy Right 2019
// 文件： CommentImageRepository.cs
// 项目名称：斑马车务
// 创建时间：2019/10/10
// 负责人：liucx
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using YouWei.Infrastructure.Entity;
using Dapper.Extensions;
using Dapper;

namespace YouWei.Infrastructure.Repository
{
    /// <summary>
    ///内容图片 仓储层
    /// </summary>	
    public class CommentImageRepository : BaseRepository<CommentImage>
    {

        #region 构造

        public CommentImageRepository() : base() { }

        public CommentImageRepository(string connectionString) : base(connectionString) { }

        public CommentImageRepository(DatabaseContext dbContext) : base(dbContext) { }

        #endregion
        /// <summary>
        /// 根据内容ID查询图片列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="commentId"></param>
        /// <returns></returns>
        public List<CommentImage> PagesByCommentID(int CommentID)
        {
            StringBuilder sb = new StringBuilder("SELECT * FROM [CommentImage] T1 WITH(NOLOCK) ");
            sb.Append(" WHERE T1.IsActvie=1 AND T1.CommentID = @CommentID");
            sb.Append(" ORDER BY T1.ImageSort ASC");
            return Query(sb.ToString(), new { CommentID });
        }
        /// <summary>
        /// 根据多个内容ID查询图片列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public List<CommentImage> PagesByCommentIDs(string ids)
        {
            StringBuilder sb = new StringBuilder("SELECT * FROM [CommentImage] T1 WITH(NOLOCK) ");
            sb.Append(" WHERE T1.IsActvie=1 AND T1.CommentID in ("+ids+")");
            sb.Append(" ORDER BY T1.ImageSort ASC");
            return Query(sb.ToString());
        }
        /// <summary>
        /// 根据文章ID删除图片
        /// </summary>
        /// <param name="CommentID"></param>
        /// <returns></returns>
        public int DeleteByCommentID(int CommentID)
        {
            StringBuilder sb = new StringBuilder("delete from  CommentImage  where CommentID=@CommentID");
            return Execute(sb.ToString(),new { CommentID });
        }
    }
}